﻿using System.IO;
using System.Web;
using System.Web.SessionState;

namespace PmfWeb.Core.HttpHandlers
{
    ///<summary>
    /// 充值网关
    ///</summary>
    public class GatePay : IHttpHandler, IRequiresSessionState
    {
        ///<summary>
        /// 开始处理请求
        ///</summary>
        ///<param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            string temp = context.Session["temp"].ToString();
            string encryptString = context.Request.QueryString["User"];
            
            if (temp != "" && context.Request.Files.Count > 0)
            {
                string uploadPath = context.Server.MapPath(context.Request.ApplicationPath + @"/Upload/" + temp);
                if (Directory.Exists(uploadPath) == false)
                {
                    Directory.CreateDirectory(uploadPath);
                }
                for (int j = 0; j < context.Request.Files.Count; j++)
                {
                    HttpPostedFile uploadFile = context.Request.Files[j];
                    if (uploadFile.ContentLength > 0)
                    {
                        uploadFile.SaveAs(Path.Combine(uploadPath, uploadFile.FileName));
                    }
                }
            }
        }

        /// <summary>
        /// 是否缓存过滤
        /// </summary>
        public bool IsReusable
        {
            get { return true;}
        }
    }
}
